<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>代理商信息</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<jsp:include page="${pageContext.request.contextPath }/resource_path.jsp" flush="true" />

<style type="text/css">
.layui-upload-img {
	width: 92px;
	height: 92px;
	margin: 0 25px 10px 10px;
}

form {
	width:90%
}

form .layui-form-label{
	width: 155px;
	text-align:center;
}

.btnGrp{
	/* margin:0 auto; */
	/* text-align:center; */
	margin-left: 320px;
}

</style>
</head>
<body class="">
	<span class="layui-breadcrumb"> <a href="">首页</a> <a> <cite>代理商信息</cite>
	</a>
	</span>
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;"></fieldset>
		<div class="x-body">
      <div style="margin-bottom: 18px">
	<div class="layui-input-inline">
	<label class="layui-label" style="margin-left: 10px;">代理厂家</label>
    <div class="layui-input-inline">
      <input type="text" name="searchName" id="searchName" placeholder="请输入代理厂家名称" autocomplete="off" class="layui-input">
    </div>
	</div>
    <button class="layui-btn layui-btn-normal" data-type="reload" id="search"><i class="layui-icon">&#xe615;</i>检索</button>
    <button class="layui-btn layui-btn" id="add"><i class="layui-icon">&#xe654;</i>新增</button>
	
	<!-- 表格 -->
	<table class="layui-hide" id="tableList" lay-filter="tableList"></table>
	</div>
	</div>
	<!-- 工具栏 -->
	<script type="text/html" id="rowToolbar">
		<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
		<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
		<!-- 
		<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="look">查看</a>
		 -->
	</script>

	<!-- 新增框 -->
	<div id="addDiv" hidden="hidden">
		<form class="layui-form" action="" lay-filter="addForm">
		<div class="layui-form-item" style="display:none">
			<label class="layui-form-label">代理厂家id</label>
			<div class="layui-input-inline">
				<input type="text" name="agentId" autocomplete="off" class="layui-input" > 
			</div>
		</div>
		<div class="layui-tab layui-tab-card" >
		  <ul class="layui-tab-title">
		    <li class="layui-this">代理厂家信息</li>
		    <li>代理厂家证件信息</li>
		    <li>其他信息</li>
		    <li>图片信息</li>
		  </ul>
		  <div class="layui-tab-content" >
		    <div class="layui-tab-item layui-show">
		    <!-- 代理厂家信息 -->
		    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
				  <legend>代理厂家信息</legend>
				</fieldset>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">代理厂家名称</label>
						<div class="layui-input-inline">
							<input type="text" name="name" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>`
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">类型</label>
						<div class="layui-input-inline">
							<input type="text" name="type" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>
					</div>					
				</div>
				
				
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">联系人</label>
						<div class="layui-input-inline">
							<input type="text" name="contact" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">联系人电话</label>
						<div class="layui-input-inline">
							<input type="text" name="phoneNum" lay-verify="required|phone"
								autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>
				
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">许可证号</label>
						<div class="layui-input-inline">
							<input type="text" name="licenseKey" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">许可证有效期</label>
						<div class="layui-input-inline">
							<input type="text" name="licenseTerm" lay-verify="date"
								 placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>			
				
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">开户行</label>
						<div class="layui-input-inline">
							<input type="text" name="depositBank" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">账号</label>
						<div class="layui-input-inline">
							<input type="text" name="bankAccount" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>	
				
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">地址</label>
						<div class="layui-input-inline">
							<input type="text" name="address" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">电话</label>
						<div class="layui-input-inline">
							<input type="text" name="landline" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>	

				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">税务登记号</label>
						<div class="layui-input-inline">
							<input type="text" name="taxNum" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">三证合一号码</label>
						<div class="layui-input-inline">
							<input type="text" name="threeToOneNum" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>
				
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">法人</label>
						<div class="layui-input-inline">
							<input type="text" name="corporation" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">法人联系座机</label>
						<div class="layui-input-inline">
							<input type="text" name="coLandline" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>	
				
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">法人手机</label>
						<div class="layui-input-inline">
							<input type="text" name="coPhoneNum" lay-verify="required|phone"
								autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">院区标记</label>
						<div class="layui-input-inline">
							<input type="text" name="zoneMark" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>
					</div>

				</div>
				
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">开通类型</label>
						<div class="layui-input-inline">
							<select name="openType" lay-verify="required" lay-search="">
					          <option value="">请选择开通类型</option><!-- （AAA、BBB、CCC、DDD、医用耗材、FFF） -->
					          <option value="AAA">AAA</option>
					          <option value="BBB">BBB</option>
					          <option value="CCC">CCC</option>
					          <option value="医用耗材">医用耗材</option>
					          <option value="FFF">FFF</option>
					        </select>
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">经营范围</label>
						<div class="layui-input-inline">
							<input type="text" name="zoneMark" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>
    
		    </div>
		    
		    <div class="layui-tab-item">
		    <!-- 代理厂家证件信息 -->
		    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
				  <legend>代理厂家证件信息</legend>
				</fieldset>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">医疗器械经营许可证号</label>
						<div class="layui-input-inline">
							<input type="text" name="productionLicenceNum" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">医疗器械经营许可证效期</label>
						<div class="layui-input-inline">
							<input type="text" name="ProductionLicenceTerm" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>	
				
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">营业执照号</label>
						<div class="layui-input-inline">
							<input type="text" name="businessLicenseNum" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">营业执照有效期</label>
						<div class="layui-input-inline">
							<input type="text" name="businessLicenseTerm" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>
				
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">授权号</label>
						<div class="layui-input-inline">
							<input type="text" name="authorizationNum" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">授权期</label>
						<div class="layui-input-inline">
							<input type="text" name="authorizationTerm" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>
				
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">信用期</label>
						<div class="layui-input-inline">
							<input type="text" name="creditValidity" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">信用额</label>
						<div class="layui-input-inline">
							<input type="text" name="creditLimit" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>		    
			</div>
			
		    <div class="layui-tab-item">
			<!-- 其他信息 -->
				<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
				  <legend>销售人员委托书信息</legend>
				</fieldset>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">姓名</label>
						<div class="layui-input-inline">
							<input type="text" name="saleman" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">身份证号码</label>
						<div class="layui-input-inline">
							<input type="text" name="salemanIdCardNum" lay-verify="required|identity"
								placeholder="" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">手机</label>
						<div class="layui-input-inline">
							<input type="text" name="salemanPhone" lay-verify="required|phone"
								autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">授权截止日期</label>
						<div class="layui-input-inline">
							<input type="text" name="salemanLicenseTerm" lay-verify="required|date"
								placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>
				
				<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
				  <legend>质量认证信息</legend>
				</fieldset>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">证号</label>
						<div class="layui-input-inline">
							<input type="text" name="qualityMsgNum" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">日期</label>
						<div class="layui-input-inline">
							<input type="text" name="qualityMsgDate" lay-verify="required|date"
								placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>
				
				<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
				  <legend>药监局备案信息</legend>
				</fieldset>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">证号</label>
						<div class="layui-input-inline">
							<input type="text" name="FDAId" lay-verify="required"
								autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">日期</label>
						<div class="layui-input-inline">
							<input type="text" name="FDADate" lay-verify="required|date"
								placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-form-item layui-form-text">
					    <label class="layui-form-label">备注</label>
					    <div class="layui-input-inline">
					      <textarea name="remarks" placeholder="请输入内容" class="layui-textarea"></textarea>
					    </div>
					 </div>
					
					
				</div>				
				
			</div>
		    <div class="layui-tab-item">
		    <!-- 图片信息 -->
			<!-- 
				营业执照 : 
				经营许可证 : 
				质量认证 : 
				制造商授权函 : 
				药监局备案 : 
			 -->
			 <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
				  <legend>图片信息</legend>
				</fieldset>
			<button type="button" class="layui-btn" id="addPhoto1">
				  <i class="layui-icon">&#xe67c;</i>营业执照
				</button>
				<button type="button" class="layui-btn" id="addPhoto2">
				  <i class="layui-icon">&#xe67c;</i>经营许可证
				</button>
				<button type="button" class="layui-btn" id="addPhoto3">
				  <i class="layui-icon">&#xe67c;</i>质量认证
				</button>
				<button type="button" class="layui-btn" id="addPhoto4">
				  <i class="layui-icon">&#xe67c;</i>制造商授权函
				</button>
				<button type="button" class="layui-btn" id="addPhoto5">
				  <i class="layui-icon">&#xe67c;</i>药监局备案
				</button>
				<div class="layui-upload-list">
				    <img class="layui-upload-img" id="addPhotoShow1">
				    <img class="layui-upload-img" id="addPhotoShow2">
				    <img class="layui-upload-img" id="addPhotoShow3">
				    <img class="layui-upload-img" id="addPhotoShow4">
				    <img class="layui-upload-img" id="addPhotoShow5">
				</div>
	    		</div>
		    </div>
		  </div>			
				
			<!-- 提交 -->
		   <div class="layui-form-item">
		    <div class="layui-input-inline btnGrp">
		      <button class="layui-btn" lay-submit lay-filter="addForm">立即提交</button>
		      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
		    </div>
		  </div> 			
		</form>
	</div>


	<!-- 修改框 -->
	<div id="editDiv" hidden="hidden">
		
	</div>
	<script type="text/javascript">
		var table;
		var form;
		var layer;
		var upload;
		var laydate;
		layui.use(['element','table','form','layer','upload','laydate'],	function() {
							table = layui.table;
							form = layui.form;
							layer = layui.layer;
							laydate = layui.laydate;
							upload = layui.upload;
							//代理商信息
							var render = function(name){
							  table.render({
									elem : '#tableList'
									,url : '/json/agentInfo.json'//数据接口
									,height : 'full-120'
									//,url : '${pageContext.request.contextPath }/agent/getAgentList.do' //数据接口 
									,toolbar : '#toolbar'
									,page : true //开启分页
									,id:'contenttable'
									,limits:[10,20,30]
									//,where:{"name":name}
								 	,request: {   //如果无需自定义请求参数，可不加该参数
						                pageName: 'page' //页码的参数名称，默认：page
						                ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
						            }
						            ,response: {   //如果无需自定义数据响应名称，可不加该参数
						                countName: 'total' //规定数据总数的字段名称，默认：count
						                ,dataName: 'rows' //规定数据列表的字段名称，默认：data
						            } 
						            ,done:function(){
						    	    	$('th').css({
						                    'background-color': '#009688', 'color': '#fff','font-weight':'bold',
						                })
						    	    }
									,cols : [ [ //表头
									{
										field : 'agentId'
										,title : 'ID'
										,width : 80
										,sort : true
										,fixed : 'left'
										,rowspan : 2
										,hide:true
										,type:'checkbox'
									}, {
										field : 'name',
										title : '名称',
										width : 80,
										sort : true,
										rowspan : 2
									}, {
										field : 'type',
										title : '类型',
										width : 80,
										sort : true,
										rowspan : 2
									}, {
										field : 'contact',
										title : '联系人',
										width : 80,
										rowspan : 2
									}, {
										field : 'phoneNum',
										title : '电话',
										width : 177,
										rowspan : 2
									}, {
										field : 'licenseKey',
										title : '许可证号',
										width : 177,
										rowspan : 2
									}, {
										field : 'licenseTerm',
										title : '许可证有效期',
										width : 135,
										sort : true,
										rowspan : 2
									}, {
										field : 'depositBank',
										title : '开户行',
										width : 177,
										rowspan : 2
									}, {
										field : 'address',
										title : '地址',
										width : 135,
										sort : true,
										rowspan : 2
									}, {
										field : 'landline',
										title : '电话',
										width : 135,
										sort : true,
										rowspan : 2
									}, {
										field : 'threeToOneNum',
										title : '三证合一号码',
										width : 135,
										sort : true,
										rowspan : 2
									}, {
										field : 'corporation',
										title : '法人',
										width : 135,
										sort : true,
										rowspan : 2
									}, {
										field : 'coLandline',
										title : '联系座机',
										width : 135,
										sort : true,
										rowspan : 2
									}, {
										field : 'coPhoneNum',
										title : '法人手机',
										width : 135,
										sort : true,
										rowspan : 2
									}, {
										field : 'productionLicenceNum',
										title : '医疗器械经营许可证号 ',
										width : 177,
										sort : true,
										rowspan : 2
									}, {
										field : 'ProductionLicenceTerm',
										title : '许可证效期',
										width : 135,
										sort : true,
										rowspan : 2
									}, {
										field : 'businessLicenseNum',
										title : '营业执照号',
										width : 177,
										sort : true,
										rowspan : 2
									}, {
										field : 'businessLicenseTerm',
										title : '营业执照效期',
										width : 135,
										sort : true,
										rowspan : 2
									}, {
										field : 'authorizationNum',
										title : '授权号',
										width : 177,
										sort : true,
										rowspan : 2
									}, {
										field : 'authorizationTerm',
										title : '授权期',
										width : 135,
										sort : true,
										rowspan : 2
									}, {
										field : 'creditValidity',
										title : '信用期',
										width : 135,
										sort : true,
										rowspan : 2
									}, {
										field : 'creditLimit',
										title : '信用额',
										width : 135,
										sort : true,
										rowspan : 2
									}, {
										field : 'zoneMark',
										title : '院区标记',
										width : 135,
										sort : true,
										rowspan : 2
									}, {
										field : 'openType',
										title : '开通类型',
										width : 135,
										sort : true,
										rowspan : 2
									}//这里要用勾选的形式 开通类型（AAA、BBB、CCC、DDD、医用耗材、FFF）
									, {
										align : 'saleManPowerOfAttorney',
										title : '销售人员委托书信息',
										colspan : 4,
										align:'center'
									} //colspan即横跨的单元格数，这种情况下不用设置field和width
									, {
										align : 'qualityMsg',
										title : '质量认证信息',
										colspan : 2,
										align:'center'
									}, {
										align : 'FDAMsg',
										title : '药监局备案信息',
										colspan : 2,
										align:'center'
									}, {
										field : 'lineOfBusiness',
										title : '经营范围',
										width : 135,
										sort : true,
										rowspan : 2,
										align:'center'
									}, {
										field : 'remarks',
										title : '备注',
										width : 135,
										sort : true,
										rowspan : 2
									}, {
										field : 'right',
										title : '操作',
										toolbar : '#rowToolbar',
										width : 135,
										rowspan : 2,
										align:'center'
									} // rowToolbar
									], [
									//销售人员委托书信息
									{
										field : 'saleman',
										title : '姓名',
										width : 80
									}, {
										field : 'salemanIdCardNum',
										title : '身份证号码',
										width : 177
									}, {
										field : 'salemanPhone',
										title : '手机',
										width : 80
									}, {
										field : 'salemanLicenseTerm',
										title : '授权截至日期',
										width : 135
									}
	
									//质量认证信息
									, {
										field : 'qualityMsgNum',
										title : '证号',
										width : 177
									}, {
										field : 'qualityMsgDate',
										title : '日期',
										width : 80
									}
									//药监局备案信息
									, {
										field : 'FDAId',
										title : '证号',
										width : 177
									}, {
										field : 'FDADate',
										title : '日期',
										width : 80
									} ] ]
								});
							}
							render("");

							// 监听工具行事件
							table.on('tool(tableList)', function(obj) {
								var data = obj.data;
								var layEvent = obj.event;
								var tr = obj.tr;

								// 删除
								if (layEvent === 'del') {
									layer.confirm('真的删除行么',function(index) {
										layer.close(index);
										//向服务端发送删除指令
										$.ajax({
											type : 'post',
											/* url: "${pageContext.request.contextPath }/login/pclogin.do",*/
											url : '${pageContext.request.contextPath }/agent/delAgent.do',
											data : {
												"agentId" : data.agentId
											},
											success : function(data) {
												console.log("agentInfo.jsp 监听工具行事件删除 ： ajax返回值 data：");
												console.log(data);
												if (data > 0) {
													toastr.success("删除成功！");
													obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
												} else {
													toastr.warning("删除失败！");
												}
												render("");
											}
											,error:function(data){
												toastr.warning("操作失败！ "+data.status+" "+data.statusText);
												console.log("Error : "+data.status+" "+data.statusText+" 详细信息：")
												console.log(data)
											}
										})
									});
								}
								
								if(layEvent === 'edit') {
									//填充数值
									
									layer.open({
										type:1
										,title:"编辑"
										,content: $('#addDiv')
										,area:['80%','100%']
										,shade:['0.3','#e2e2e2']
										,maxmin:true
										,anim:1
										,end:function(){
											var formDiv = document.getElementById('#addDiv');
											formDiv.style.display = '';
										},success:function(){
/* 											$("[name='agentId']").val(data.agentId);
											$("[name='name']").val(data.name);
											$("[name='type']").val(data.type);
											$("[name='taxNum']").val(data.taxNum);
											$("[name='contact']").val(data.contact);
											$("[name='phoneNum']").val(data.phoneNum);
											$("[name='licenseKey']").val(data.licenseKey);
											$("[name='licenseTerm']").val(data.licenseTerm);
											$("[name='depositBank']").val(data.depositBank);
											$("[name='bankAccount']").val(data.bankAccount);
											$("[name='address']").val(data.address);
											$("[name='landline']").val(data.landline);
											$("[name='threeToOneNum']").val(data.threeToOneNum);
											$("[name='corporation']").val(data.corporation);
											$("[name='coLandline']").val(data.coLandline);
											$("[name='coPhoneNum']").val(data.coPhoneNum);
											$("[name='productionLicenceNum']").val(data.productionLicenceNum);
											$("[name='ProductionLicenceTerm']").val(data.ProductionLicenceTerm);
											$("[name='businessLicenseNum']").val(data.businessLicenseNum);
											$("[name='businessLicenseTerm']").val(data.businessLicenseTerm);
											$("[name='authorizationNum']").val(data.authorizationNum);
											$("[name='authorizationTerm']").val(data.authorizationTerm);
											$("[name='creditValidity']").val(data.creditValidity);
											$("[name='creditLimit']").val(data.creditLimit);
											$("[name='openType']").val(data.openType);
											$("[name='saleManPowerOfAttorney']").val(data.saleManPowerOfAttorney);
											$("[name='saleman']").val(data.saleman);
											$("[name='salemanIdCardNum']").val(data.salemanIdCardNum);
											$("[name='salemanPhone']").val(data.salemanPhone);
											$("[name='salemanLicenseTerm']").val(data.salemanLicenseTerm);
											$("[name='qualityMsg']").val(data.qualityMsg);
											$("[name='qualityMsgNum']").val(data.qualityMsgNum);
											$("[name='qualityMsgDate']").val(data.qualityMsgDate);
											$("[name='FDAMsg']").val(data.FDAMsg);
											$("[name='FDAId']").val(data.FDAId);
											$("[name='FDADate']").val(data.FDADate);
											$("[name='lineOfBusiness']").val(data.lineOfBusiness);
											$("[name='remarks']").val(data.remarks); */
											//使用form.val赋值
											form.val("addForm",{
												"agentId" : data.agentId
												,"name" : data.name
												,"type" : data.type
												,"taxNum" : data.taxNum
												,"contact" : data.contact
												,"phoneNum" : data.phoneNum
												,"licenseKey" : data.licenseKey
												,"licenseTerm" : data.licenseTerm
												,"depositBank" : data.depositBank
												,"bankAccount" : data.bankAccount
												,"address" : data.address
												,"landline" : data.landline
												,"threeToOneNum" : data.threeToOneNum
												,"corporation" : data.corporation
												,"coLandline" : data.coLandline
												,"coPhoneNum" : data.coPhoneNum
												,"productionLicenceNum" : data.productionLicenceNum
												,"ProductionLicenceTerm" : data.ProductionLicenceTerm
												,"businessLicenseNum" : data.businessLicenseNum
												,"businessLicenseTerm" : data.businessLicenseTerm
												,"authorizationNum" : data.authorizationNum
												,"authorizationTerm" : data.authorizationTerm
												,"creditValidity" : data.creditValidity
												,"creditLimit" : data.creditLimit
												,"openType" : data.openType
												,"saleManPowerOfAttorney" : data.saleManPowerOfAttorney
												,"saleman" : data.saleman
												,"salemanIdCardNum" : data.salemanIdCardNum
												,"salemanPhone" : data.salemanPhone
												,"salemanLicenseTerm" : data.salemanLicenseTerm
												,"qualityMsg" : data.qualityMsg
												,"qualityMsgNum" : data.qualityMsgNum
												,"qualityMsgDate" : data.qualityMsgDate
												,"FDAMsg" : data.FDAMsg
												,"FDAId" : data.FDAId
												,"FDADate" : data.FDADate
												,"lineOfBusiness" : data.lineOfBusiness
												,"remarks" : data.remarks
											});
											
										}
									});
								}

								// 修改
							});
							//监听搜索摁钮事件
							$("#search").click(function(){
								/* var name = $("#search").getElementById("searchName"); */
								var name = document.getElementById("searchName").value;
								console.info(name);
								if(name!=null&&name.length>=0){
									table.reload('contenttable', {
									  url: '${pageContext.request.contextPath }/agent/getAgentList.do'
									  ,where: {'name':name} //设定异步数据接口的额外参数
									});
								}
							});
							
							// 监听新增按钮事件
							$("#add").click(function(){
								layer.open({
									type:1
									,title:'新建'
									,content: $('#addDiv')
									,area:['80%','100%']
									,shade:['0.3','#e2e2e2']
									,maxmin:true
									,anim:1
									,end:function(){
										var formDiv = document.getElementById('addDiv');
										formDiv.style.display = '';
									}
									
								});
							});
							

							
							
							//监听添加表格事件
							form.on('submit(addForm)',function(data){
								console.log(data);
								$.ajax({
									type : 'post',
									url : '${pageContext.request.contextPath }/agent/addAgent.do',
									data : data.field,
									success : function(data){
										if(data > 0){
											toastr.success("添加成功！");
											obj.del();
										}else{
											toastr.warning("添加失败！");
										}
									}
									,error:function(data){
										toastr.warning("操作失败！ "+data.status+" "+data.statusText);
										console.log("Error : "+data.status+" "+data.statusText+" 详细信息：")
										console.log(data)
									}
								});
								
							});

							
							//上传组件,这里利用拼接字符串，批量生成
							var s1 = "#addPhoto";
							var s2 = "#addPhotoShow";
							for(i = 1; i < 6; i++){
								var s3 = s1 + i;
								var s4 = s2 + i;
								upload.render({//upload.render
									elem:s3
									,url:''//上传图片接口
									,before:function(obj){
										//本地预览
										obj.preview(function(index,file,result){
											$(s4).attr('src',result);//图片链接
										})
									}
									,done:function(res){
										if(res.code > 0){
											return layer.msg('上传失败');
										}
									}
								});
							}
							 
							 
							 // 使用laydate组件
							 var laydatefun = function(element){
								 
								 //console.info("element"+i+":::"+element)
							 	laydate.render({
									 elem : document.getElementsByName(element)[0],
									 format: 'yyyy-MM-dd',
									 type: 'date'
							 	});
							 }
							 //利用数组给所有日期组件添加声明
							 //许可证有效期    licenseTerm,许可证效期    ProductionLicenceTerm,营业执照效期    businessLicenseTerm,授权期    authorizationTerm,授权截至日期    salemanLicenseTerm
							 //质量认证信息日期    qualityMsgDate,药监局备案信息日期    FDADate
							 var dateArray = ['licenseTerm','ProductionLicenceTerm','businessLicenseTerm','authorizationTerm','salemanLicenseTerm','qualityMsgDate','FDADate'];
							 for(i = 0;i<dateArray.length;i++){
								 var str = dateArray[i];
								 laydatefun(str);
							 }
							 
						});
	</script>
</body>
</html>